<script setup lang="ts">
import { computed, inject, onMounted, onUnmounted, toRef } from 'vue';
const data: any = inject('data');
const info = computed(() => {
  return data.value.pc_pco_pcb_list || []
})
const pc_pco_pcc_obj = computed(() => {
  return data.value.pc_pco_pcc_obj || {}
})
const pc_pco_pcd_list = computed(() => {
  return data.value.pc_pco_pcd_list || []
})
let count = 0
onUnmounted(() => {
  count = 0
})

function numberToChinese(num) {
  const chineseNumArr = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
 
  if (num < 10) {
    return chineseNumArr[num];
  }
 
  if (num < 100) {
    let tens = Math.floor(num / 10);
    let remainder = num % 10;
    let result = chineseNumArr[tens] + '十';
    if (remainder !== 0) {
      result += chineseNumArr[remainder];
    }
    return result;
  }
 
  if (num < 1000) {
    let hundreds = Math.floor(num / 100);
    let remainder = num % 100;
    let result = chineseNumArr[hundreds] + '百';
    if (remainder !== 0) {
      result += numberToChinese(remainder);
    }
    return result;
  }
}
function format(val){
  if(val == '循环额度下分账户' || val == '循环贷账户'){
    count++
    return '循环贷账户'+ numberToChinese(count)
  }
  return val
}


</script>
<template>
  <div class="h3 title">（2）信贷交易违约信息概要</div>
  <table>
    <caption>
      被追偿信息汇总
    </caption>
    <tbody>

      <tr>
        <th colspan="2">业务类型</th>
        <th colspan="2">账户数</th>
        <th>余额</th>
      </tr>
      <tr v-for="(item, i) in info" :key="i">
        <td colspan="2">{{ item.PC02BD01 }}</td>
        <td colspan="2">{{ item.PC02BS03 }}</td>
        <td>{{ item.PC02BJ02 }}</td>
      </tr>


    </tbody>

  </table>


  <table>
    <caption>呆账信息汇总</caption>
    <tbody>
      <tr>
        <th colspan="3">账户数</th>
        <th colspan="2">余额</th>
      </tr>
      <tr>
        <td colspan="3">{{ pc_pco_pcc_obj.PC02CS01 }}</td>
        <td colspan="2">{{ pc_pco_pcc_obj.PC02CJ01 }}</td>
      </tr>
    </tbody>
  </table>

  <table>
    <caption>
      逾期（透支）信息汇总
    </caption>
    <tbody>

      <tr>
        <th>账户类型</th>
        <th>账户数</th>
        <th>月份数</th>
        <th>单月最高逾期/透支总额</th>
        <th>最长逾期/透支月数</th>
      </tr>
      <tr v-for="(item, i) in pc_pco_pcd_list" :key="i">
        <td>{{ format(item.PC02DD01) }}</td>
        <td>{{ item.PC02DS02 }}</td>
        <td>{{ item.PC02DS03 }}</td>
        <td>{{ item.PC02DJ01 }}</td>
        <td>{{ item.PC02DS04 }}</td>
      </tr>
    </tbody>
  </table>
</template>